extends "../scopebase/scopebase.gd"
var cnt = 0
var norc = 0
func init():
	.init()
	name = "望远镜"
	resetdata()
	att.maxHp = 50
	att.atk = 17
	att.atkRan = 2
	info = "战况勘察：<先手>攻击范围内所有队友忽略<模糊>，增伤增加10%，持续2s[cd:5秒]\n"
	info = info + "[color=#666666]射手系专属：距离越远伤害加成越高（除技能伤害外，1格5%，2格12%，3格18%，其他23%）；普攻有20%概率击中弱点额外造成50%物理伤害[未解锁][/color]"

func _connect():
	._connect()
	if masCha.id.find("cTDR") != -1 || masCha.id == "cex___Hide_SaintRanger":
		masCha.connect("onBattleStart",self,"sszs")
		info = info.replace("[color=#666666]射手系专属：距离越远伤害加成越高（除技能伤害外，1格5%，2格12%，3格18%，其他23%）；普攻有20%概率击中弱点额外造成50%物理伤害[未解锁][/color]","[color=#FFA500]射手系专属：距离越远伤害加成越高（除技能伤害外，1格5%，2格12%，3格18%，其他23%）；普攻有20%概率击中弱点额外造成50%物理伤害[已解锁][/color]")
	else:
		info = info.replace("[color=#FFA500]射手系专属：距离越远伤害加成越高（除技能伤害外，1格5%，2格12%，3格18%，其他23%）；普攻有20%概率击中弱点额外造成50%物理伤害[已解锁][/color]","[color=#666666]射手系专属：距离越远伤害加成越高（除技能伤害外，1格5%，2格12%，3格18%，其他23%）；普攻有20%概率击中弱点额外造成50%物理伤害[未解锁][/color]")
	sys.main.connect("onBattleStart",self,"resetcnt")
	

func resetcnt():
	cnt = 0
	norc = 0
	zkkc()

func _upS():
	._upS()
	cnt += 1
	if cnt == 5:
		cnt = 0
		zkkc()

func zkkc():
	var chas = masCha.getCellChas(masCha.cell,masCha.att.atkRan,2)
	if self.id == "i_TD_scope3_Hide_MAX":
		chas = masCha.getAllChas(2)
	for i in chas:
		i.addBuff(b_qx.new(1))

func sszs():
	masCha.addBuff(WYJSSZS.new(1))

class WYJSSZS extends Buff:
	var canremove:bool = false
	func _init(lv):
		attInit()
		id = "WYJSSZS"

	func _connect():
		masCha.connect("onAtkChara",self,"run")

	func run(atkinfo):
		if atkinfo.atkType == Chara.AtkType.SKILL:return
		atkinfo.hurtVal *= getpw(atkinfo.hitCha.cell,masCha.cell)
		if atkinfo.atkType == Chara.AtkType.NORMAL && !atkinfo.isMiss:
			if sys.rndPer(20):
				masCha.hurtChara(atkinfo.hitCha,masCha.att.atk*0.5,Chara.HurtType.PHY,Chara.AtkType.EFF)

	func getpw(c1,c2):
		var pws = 1.05
		var x = abs(c1.x - c2.x)
		var y = abs(c1.y - c2.y)
		var k = x*x + y*y
		if k >= 4:
			pws += 0.07
		if k >= 9:
			pws += 0.06
		if k >= 16:
			pws += 0.05
		return pws

class b_qx extends Buff:
	var canremove:bool = false
	func _init(lv):
		attInit()
		life = lv * 2.0
		id = "b_qx"
		att.atkR = 0.1